this.BX=this.BX||{};(function(e,t,i,a,n,s,o,r,c){"use strict";var d=function(){function e(t){var i=this;babelHelpers.classCallCheck(this,e);this.clientNode=t.clientNode;this.avatarNode=t.avatarNode;this.accountNode=t.accountNode;this.instagramAccountNode=t.instagramAccountNode;this.linkNode=t.linkNode;this.provider=t.provider;this.componentName=t.componentName;this.signedParameters=t.signedParameters;this.uiNodes=t.uiNodes;this._helper=u.getInstance(this,[]);this.loaded=[];this.clientSelector=new BX.Seo.Ads.ClientSelector(t.clientBlock,{selected:this.provider.PROFILE,items:this.provider.CLIENTS,canAddItems:true,events:{onNewItem:function e(){a.LoginFactory.getLoginObject(i.provider).login()},onSelectItem:function e(t){i.setProfile(t)},onRemoveItem:function e(t){i.logout(t.CLIENT_ID)}}});return this}babelHelpers.createClass(e,[{key:"listenSeoAuth",value:function e(){BX.addCustomEvent(window,"seo-client-auth-result",BX.proxy(this.onSeoAuth,this))}},{key:"onSeoAuth",value:function e(t){t.reload=false;this.getProvider(t.clientId)}},{key:"logout",value:function e(t){var i=this;var a=!(this.provider.TYPE==="facebook"||this.provider.TYPE==="instagram")?{}:{connect:"FBE",action:"disconnect",type:"disconnect"};this._helper.showBlock("loading");this._helper.request("logout",{logoutClientId:t},(function(e){i.provider=e;if(i.clientSelector){i.clientSelector.setSelected(i.provider.PROFILE);i.clientSelector.setItems(i.provider.CLIENTS)}i._helper.setProvider(e);i._helper.showBlockByAuth()}),a)}},{key:"getProvider",value:function e(t){var i=this;this.showBlock("loading");this.request("getProvider",{},(function(e){i.provider=e;if(i.clientSelector){if(!i.provider.PROFILE||t&&t!==i.provider.PROFILE.CLIENT_ID){for(var a=0;a<i.provider.CLIENTS.length;a++){var n=i.provider.CLIENTS[a];if(!t||t.toString()===n.CLIENT_ID.toString()){i.setProfile(n);break}}}i.clientSelector.setSelected(i.provider.PROFILE);i.clientSelector.setItems(i.provider.CLIENTS)}i.showBlockByAuth()}))}},{key:"loadAccounts",value:function e(t){var i=this;if(this.clientSelector){this.clientSelector.disable()}this._helper.request("getAccounts",{},(function(e){if(i.clientSelector){i.clientSelector.enable()}i.uiNodes.accountNotice.ad.style.display="none";if(!e.length){i.uiNodes.accountNotice.ad.style.display="block";return}var t=e.map((function(e){return{caption:BX.util.htmlspecialchars(e.name),value:e.id,selected:e.id===i.accountId,currency:e.currency}}),i);i._helper.fillDropDownControl(i.accountNode,t);if(t.length>0){setTimeout((function(){BX.fireEvent(i.accountNode,"change")}),150)}i.accountNode.disabled=false}))}},{key:"loadInstagramAccounts",value:function e(t){var i=this;if(this.clientSelector){this.clientSelector.disable()}this._helper.request("getInstagramAccounts",{},(function(e){if(i.clientSelector){i.clientSelector.enable()}i.uiNodes.accountNotice.instagram.style.display="none";if(!e.length){i.uiNodes.accountNotice.instagram.style.display="block";return}var t=e.map((function(e){return{caption:BX.util.htmlspecialchars(e.name),value:e.id,pageId:e.page_id,actorId:e.actor_id}}),i);i._helper.fillDropDownControl(i.instagramAccountNode,t);if(t.length>0){setTimeout((function(){BX.fireEvent(i.instagramAccountNode,"change")}),150)}i.instagramAccountNode.disabled=false}))}},{key:"loadSettings",value:function e(){this.instagramAccountNode.disabled=true;this.accountNode.disabled=true;var t=this.provider.TYPE;var i=this.provider.IS_SUPPORT_ACCOUNT;if(!this.provider.PROFILE){return}if(!this.loaded.includes(t)){this.loaded.push(t)}if(this.accountNode&&i){this.loadAccounts();this.loadInstagramAccounts()}}},{key:"setProfile",value:function e(t){this.clientId=t&&t.CLIENT_ID?t.CLIENT_ID:null;this.provider.PROFILE=t;this.accountId=null;this.pageId=null;if(this.clientSelector.selected){this._helper.showBlockMain()}this.clientSelector.setSelected(t)}}]);return e}();var l;var u=function(){function e(t){babelHelpers.classCallCheck(this,e);this.provider=t.provider;this.clientId=t.clientId;this.clientSelector=t.clientSelector;this.clientNode=t.clientNode;this.avatarNode=t.avatarNode;this.linkNode=t.linkNode;this.seoAccount=t;this.signedParameters=t.signedParameters;this.containerNode=BX("crm-ads-new-campaign");this.mess={errorAction:r.Loc.getMessage("UI_HELPER_ERROR_MSG"),dlgBtnClose:r.Loc.getMessage("UI_HELPER_BUTTON_CLOSE")};return this}babelHelpers.createClass(e,[{key:"setProvider",value:function e(t){this.provider=t}},{key:"request",value:function e(t,i,a,n){var s=this;i.action=t;i.type=this.seoAccount.provider.TYPE;i.clientId=this.seoAccount.clientId;this.sendActionRequest(t,i,(function(e){return s.onResponse(e,a)}),null,n||{})}},{key:"onResponse",value:function e(t,i){if(!t.error){i.apply(this,[t.data])}}},{key:"sendActionRequest",value:function e(t,i,a,n,s){var o=this;a=a||null;n=n||BX.proxy(this.showErrorPopup,this);i=i||{};s=s||{};BX.ajax.runComponentAction(this.seoAccount.componentName,t,{mode:"class",signedParameters:this.signedParameters,data:i,analyticsLabel:s}).then((function(e){var t=e.data||{};if(t.error){n.apply(o,[t])}else if(a){a.apply(o,[t])}}),(function(){var e={error:true,text:""};n.apply(o,[e])}))}},{key:"showErrorPopup",value:function e(a){console.log(a);var n=a.text||this.mess.errorAction;var s=t.PopupManager.create({id:"crm_ads_rtg_error",autoHide:true,lightShadow:true,closeByEsc:true,overlay:{backgroundColor:"black",opacity:500},events:{onPopupClose:this.onErrorPopupClose.bind(this)},buttons:[new i.Button({text:"close"||this.mess.dlgBtnClose,events:{click:function e(){s.close()}}})]});s.setContent('<span class="crm-ads-rtg-warning-popup-alert">'.concat(n,"</span>"));s.show()}},{key:"onErrorPopupClose",value:function e(){if(this.clientSelector){this.clientSelector.enable()}}},{key:"showBlock",value:function e(t){t=r.Type.isArray(t)?t:[t];var i="data-bx-ads-block";var a=babelHelpers.toConsumableArray(this.containerNode.querySelectorAll("["+i+"]"));a.forEach((function(e){var a=e.getAttribute(i);var n=t.includes(a);e.style.display=n?e.dataset.flex?"flex":"block":"none"}),this)}},{key:"showBlockRefresh",value:function e(){this.showBlock(["auth","refresh"])}},{key:"showBlockLogin",value:function e(){this.showBlock("login");var t=BX("seo-ads-login-btn");if(t&&this.provider&&this.provider.AUTH_URL){t.setAttribute("onclick","BX.util.popup('"+this.provider.AUTH_URL+"', 800, 600);")}if(this.clientNode){this.clientNode.value=""}}},{key:"showBlockMain",value:function e(){if(this.avatarNode){this.avatarNode.style["background-image"]="url("+this.provider.PROFILE.PICTURE+")"}if(this.nameNode){this.nameNode.innerText=this.provider.PROFILE.NAME}if(this.linkNode){if(this.provider.PROFILE.LINK){this.linkNode.setAttribute("href",this.provider.PROFILE.LINK)}else{this.linkNode.removeAttribute("href")}}if(this.clientNode){this.clientNode.value=this.provider.PROFILE&&this.provider.PROFILE.CLIENT_ID?this.provider.PROFILE.CLIENT_ID:""}this.showBlock(["auth","main"]);this.seoAccount.loadSettings()}},{key:"showBlockByAuth",value:function e(){if(this.provider.HAS_AUTH){this.showBlockMain()}else{this.showBlockLogin()}}},{key:"fillDropDownControl",value:function e(t,i){i=i||[];t.innerHTML="";i.forEach((function(e){if(!e||!e.caption){return}var i=r.Tag.render(l||(l=babelHelpers.taggedTemplateLiteral(["<option value='","' selected='","'>","</option>"])),e.value,!!e.selected,e.caption);if(e.currency){i.dataset.currency=e.currency}if(e.pageId){i.dataset.pageId=e.pageId}if(e.actorId){i.dataset.actorId=e.actorId}t.appendChild(i)}))}}],[{key:"getCreated",value:function e(){if(this._instance===undefined){return null}return this._instance}},{key:"getInstance",value:function t(i,a){if(this._instance===undefined){this._instance=new e(i,a)}return this._instance}}]);return e}();var h,p,m;var g=function(){function e(t){var i=this;babelHelpers.classCallCheck(this,e);babelHelpers.defineProperty(this,"_DEFAULT_CURRENCY","RUB");babelHelpers.defineProperty(this,"_STAGES",{accountSelected:1,postSelected:2,pageSelected:3,audienceSelected:4,budgetSelected:5,toModeration:6});if(this._instance){return this._instance}this.optionSelectedClass="crm-ads-new-campaign-item-option--selected";this.containerId=t.containerId;this.provider=t.provider;this.context=t.context;this.onRequest=t.onRequest;this.componentName=t.componentName;this.signedParameters=t.signedParameters;this.postListUrl=t.postListUrl;this.audienceUrl=t.audienceUrl;this.crmAudienceUrl=t.crmAudienceUrl;this.pageConfigurationUrl=t.pageConfigurationUrl;this.mess=t.mess;this.type=t.type;this.iBlockId=t.iBlockId;this.basePriceId=t.basePriceId;this.storeExists=t.storeExists;this.isCloud=t.isCloud||false;this.clientId=t.clientId;this.accountId=t.accountId;this.baseCurrency=t.baseCurrency;this.arrows=document.querySelectorAll(".crm-ads-new-campaign-item-arrow");this.price=[];this.price[this._DEFAULT_CURRENCY]=[];this.price[this._DEFAULT_CURRENCY]["recommended"]={duration:3,value:100};this.price[this._DEFAULT_CURRENCY]["verified"]={duration:3,value:200};this.price[this._DEFAULT_CURRENCY]["boost"]={duration:3,value:300};this.price[this._DEFAULT_CURRENCY]["confident"]={duration:5,value:500};this.price["USD"]=[];this.price["USD"]["recommended"]={duration:3,value:50};this.price["USD"]["verified"]={duration:3,value:100};this.price["USD"]["boost"]={duration:3,value:150};this.price["USD"]["confident"]={duration:5,value:200};this.price["EUR"]=[];this.price["EUR"]["recommended"]={duration:3,value:50};this.price["EUR"]["verified"]={duration:3,value:100};this.price["EUR"]["boost"]={duration:3,value:150};this.price["EUR"]["confident"]={duration:5,value:200};this.completedStages={};this.selectedRegions={};this.loader={init:function e(t){i.caller=t},change:function e(t,i,a){t.style.display=a?"":"none";if(i){i.disabled=!i.options.length===0||a?false:true}}};this.init()}babelHelpers.createClass(e,[{key:"init",value:function e(){this._instance=this;this.initiateUINodes();this.initiateAutoAudienceMode();for(var t=this._STAGES.accountSelected;t<=this._STAGES.toModeration;t++){this.deActivateStage(t)}this.initiateAccounts();this.activateStage(this._STAGES.audienceSelected);this.initiateSwitcher("product");this.initiateSwitcher("audience");this.initiateSwitcher("budget");this.bindEvents();this.buildSelector();this.storeBlockShow(true)}},{key:"reInitAdCreator",value:function e(){this.adCreatorData={};this.adCreatorData.audienceConfig={};this.adCreatorData.crmAudienceConfig={}}},{key:"initiateAccounts",value:function e(){this.seoAccount=new d({clientNode:this.uiNodes.clientInput,provider:this.provider,avatarNode:this.uiNodes.avatar,linkNode:this.uiNodes.link,accountNode:this.uiNodes.account,instagramAccountNode:this.uiNodes.instagramAccount,clientBlock:this.uiNodes.clientBlock,signedParameters:this.signedParameters,componentName:this.componentName,uiNodes:this.uiNodes});this.profileConfigured=false;if(!this.clientId&&!this.provider.PROFILE){for(var t=0;t<this.provider.CLIENTS.length;t++){this.seoAccount.setProfile(this.provider.CLIENTS[t]);this.profileConfigured=true;break}}this.loader.init(this);if(this.provider.PROFILE){this.activateStage(this._STAGES.accountSelected)}if(!this.profileConfigured){this.seoAccount.setProfile(this.provider.PROFILE)}this.seoAccount._helper.showBlockByAuth()}},{key:"bindEvents",value:function e(){var t=this;r.Event.bind(this.uiNodes.addPost,"click",this.openPostSlider.bind(this));this.uiNodes.createLinks.forEach((function(e){r.Event.bind(e,"click",BX.proxy((function(){if(!this.hasPostLis){this.showBlockRefresh()}}),this))}),this);r.Event.bind(this.uiNodes.refreshButton,"click",BX.proxy((function(){this.seoAccount.getProvider()}),this));if(this.uiNodes.autoRemover.checker){r.Event.bind(this.uiNodes.autoRemover.checker,"click",(function(){var e=t.uiNodes.autoRemover;e.select.disabled=!e.checker.checked}))}r.Event.bind(this.uiNodes.logout,"click",BX.proxy((function(){this.seoAccount.logout(this.clientId)}),this));r.Event.bind(this.uiNodes.addClientBtn,"click",BX.proxy((function(){BX.util.popup(_this.provider.AUTH_URL,800,600)}),this));this.arrows.forEach((function(e){e.addEventListener("click",t.switchCollapsed)}));r.Event.bind(this.uiNodes.account,"change",this.checkCurrency.bind(this));document.querySelectorAll(".seo-ads-budget-item-block").forEach((function(e){r.Event.bind(e,"click",t.calculateTotal.bind(t))}));document.querySelectorAll(".seo-ads-audience-item-block").forEach((function(e){r.Event.bind(e,"click",t.changeAudienceMode.bind(t))}));document.querySelectorAll(".seo-ads-product-item-block").forEach((function(e){r.Event.bind(e,"click",t.changeProductSelectionMode.bind(t))}));r.Event.bind(this.uiNodes.audienceExpert,"click",this.showAudienceExpertModeForm.bind(this));r.Event.bind(this.uiNodes.productExpert,"click",this.openTargetPageSlider.bind(this));r.Event.bind(this.uiNodes.addProductBtn,"click",this.toCreateStoreSlider.bind(this));r.Event.bind(this.uiNodes.addCurrencyBtn,"click",this.addCurrency.bind(this));r.Event.bind(this.uiNodes.toModerationBtn,"click",this.sendToModeration.bind(this))}},{key:"initiateUINodes",value:function e(){this.containerNode=BX("crm-ads-new-campaign");BX.UI.Hint.init(this.containerNode);this.uiNodes={avatar:this.containerNode.querySelector("[data-bx-ads-auth-avatar]"),name:this.containerNode.querySelector("[data-bx-ads-auth-name]"),link:this.containerNode.querySelector("[data-bx-ads-auth-link]"),logout:this.containerNode.querySelector("[data-bx-ads-auth-logout]"),clientBlock:this.containerNode.querySelector("[data-bx-ads-client]"),clientInput:this.containerNode.querySelector("[data-bx-ads-client-input]"),account:this.containerNode.querySelector("[data-bx-ads-account]"),accountLoader:this.containerNode.querySelector("[data-bx-ads-account-loader]"),instagramAccount:this.containerNode.querySelector("[data-bx-ads-instagram-account]"),instagramAccountLoader:this.containerNode.querySelector("[data-bx-ads-instagram-account-loader]"),errorNotFound:this.containerNode.querySelector("[data-bx-ads-post-not-found]"),addPost:this.containerNode.querySelector(".crm-ads-new-campaign-item-post-new"),addProductBtn:this.containerNode.querySelector(".seo-ads-add-product-btn"),addCurrencyBtn:this.containerNode.querySelector(".seo-ads-currency-apply-btn"),toModerationBtn:this.containerNode.querySelector(".seo-ads-to-moderation-btn"),refreshButton:this.containerNode.querySelector("[data-bx-ads-refresh-btn]"),currencyBlock:document.querySelector(".seo-ads-currency-block"),audienceSummary:document.querySelector(".seo-ads-audience-summary"),createLinks:BX.convert.nodeListToArray(this.containerNode.querySelectorAll("[data-bx-ads-post-create-link]")),accountNotice:{instagram:this.containerNode.querySelector(".seo-ads-no-ad-account-instagram"),ad:this.containerNode.querySelector(".seo-ads-no-ad-account")},audienceExpert:BX("crm-ads-new-campaign-item-expert-audience"),productExpert:BX("crm-ads-new-campaign-item-expert-product"),budgetExpert:BX("crm-ads-new-campaign-item-expert-budget"),autoRemover:{node:this.containerNode.querySelector("[data-bx-ads-post-auto-remove]"),checker:this.containerNode.querySelector("[data-bx-ads-post-auto-remove-checker]"),select:this.containerNode.querySelector("[data-bx-ads-post-auto-remove-select]")},form:{permalink:this.containerNode.querySelector("[data-bx-ads-permalink]"),mediaId:this.containerNode.querySelector("[data-bx-ads-media-id]"),targetUrl:this.containerNode.querySelector("[data-bx-ads-target-url]"),duration:this.containerNode.querySelector("[data-bx-ads-duration]"),page:this.containerNode.querySelector("[data-bx-ads-page-id]"),body:this.containerNode.querySelector("[data-bx-ads-body]"),adsId:this.containerNode.querySelector("[data-bx-ads-id]"),pageId:this.containerNode.querySelector("[data-bx-ads-page-id]"),budget:this.containerNode.querySelector("[data-bx-ads-budget]"),ageFrom:this.containerNode.querySelector("[data-bx-ads-age-from]"),ageTo:this.containerNode.querySelector("[data-bx-ads-age-to]"),genders:this.containerNode.querySelector("[data-bx-ads-genders]"),interests:this.containerNode.querySelector("[data-bx-ads-interests]"),imageUrl:this.containerNode.querySelector("[data-bx-ads-image-url]"),instagramAccountId:this.containerNode.querySelector("[data-bx-ads-actor-id]"),segmentInclude:this.containerNode.querySelector("[data-bx-ads-segment-include]"),segmentExclude:this.containerNode.querySelector("[data-bx-ads-segment-exclude]"),regions:this.containerNode.querySelector("[data-bx-ads-regions]")},adsStoreBlock:this.containerNode.querySelectorAll(".seo-ads-store"),addClientBtn:this.containerNode.querySelector("[data-bx-ads-client-add-btn]"),addPostBtn:this.containerNode.querySelector("[data-bx-ads-post-add]")}}},{key:"initiateSwitcher",value:function e(t){new BX.UI.Switcher({node:BX("crm-ads-new-campaign-item-expert-".concat(t)),size:"small"})}},{key:"checkCurrency",value:function e(){var t=this.uiNodes.account;this.usedCurrency=t.options[t.selectedIndex].dataset.currency;this.currencyExists(this.usedCurrency)}},{key:"calculateTotal",value:function e(t){var i=this;if(this.checkInstagramAccount()){return}var a=t.target.dataset.type?t.target:t.target.parentNode;var n=a.dataset.type;var s=this.price[this.usedCurrency][n];var o=s.duration*s.value;document.querySelectorAll(".seo-ads-budget-total-value").forEach((function(e){e.textContent=o}));document.querySelector(".seo-ads-budget-total-currency").textContent=this.usedCurrency;document.querySelector(".seo-ads-budget-total-duration").textContent=s.duration;document.querySelector(".seo-ads-total-budget").textContent=o;document.querySelector(".seo-ads-total-currency").textContent=this.usedCurrency;document.querySelector(".seo-ads-total-duration").textContent=s.duration;document.querySelector(".crm-ads-new-campaign-item-cost").style.display="block";document.querySelectorAll(".seo-ads-budget-item-block").forEach((function(e){e.classList.remove(i.optionSelectedClass)}));a.classList.add(this.optionSelectedClass);this.uiNodes.form.budget.value=o;this.uiNodes.form.duration.value=s.duration;this.prepareCurrencyBlocks();this.activateStage(this._STAGES.budgetSelected)}},{key:"checkInstagramAccount",value:function e(){if(!this.uiNodes.instagramAccount.value){this.scrollToStage(this._STAGES.accountSelected);return true}return false}},{key:"changeAudienceMode",value:function e(t){var i=this;if(this.checkInstagramAccount()){return}var a=t.target.dataset.type?t.target:t.target.parentNode;var n=a.dataset.type;document.querySelectorAll(".seo-ads-audience-item-block").forEach((function(e){e.classList.remove(i.optionSelectedClass)}));a.classList.add(this.optionSelectedClass);switch(n){case"auto":this.initiateAutoAudienceMode();break;case"crm":this.showCrmAudienceExpertModeForm();break;case"expert":this.showAudienceExpertModeForm();break}}},{key:"changeProductSelectionMode",value:function e(t){var i=this;if(this.checkInstagramAccount()){return}var a=t.target.dataset.type?t.target:t.target.parentNode;var n=a.dataset.type;document.querySelectorAll(".seo-ads-product-item-block").forEach((function(e){e.classList.remove(i.optionSelectedClass)}));a.classList.add(this.optionSelectedClass);switch(n){case"auto":this.storeBlockShow(true);break;case"expert":this.openTargetPageSlider();break}}},{key:"storeBlockShow",value:function e(t){var i=this;this.uiNodes.adsStoreBlock.forEach((function(e){if(i.storeExists&&e.dataset.type==="store-not-created"){return}if(!i.storeExists&&e.dataset.type!=="store-not-created"){return}e.style.display=t?"block":"none"}))}},{key:"prepareCurrencyBlocks",value:function e(){var t=this;document.querySelectorAll(".seo-ads-current-currency").forEach((function(e){e.textContent=t.usedCurrency}))}},{key:"prepareCurrencyBlock",value:function e(){var t=arguments.length>0&&arguments[0]!==undefined?arguments[0]:this._DEFAULT_CURRENCY;if(!this.price[t]){for(var i in this.price[this._DEFAULT_CURRENCY]){this.convertToCurrency(i,this._DEFAULT_CURRENCY!==this.baseCurrency?this.baseCurrency:t,this.price[this._DEFAULT_CURRENCY][i])}return}for(var a in this.price[t]){document.querySelector(".seo-ads-budget-".concat(a,"-duration")).textContent=this.price[t][a].duration;document.querySelector(".seo-ads-budget-".concat(a,"-value")).textContent=this.price[t][a].value;document.querySelector(".seo-ads-budget-".concat(a,"-currency")).textContent=t}}},{key:"convertToCurrency",value:function e(t,i,a){var n=this;this.seoAccount._helper.request("convertCurrency",{sourceCurrency:this.baseCurrency,targetCurrency:i,amount:a.value},(function(e){var s=e.amount;if(!n.price[i]){n.price[i]=[]}if(!n.price[i][t]){n.price[i][t]={duration:a.duration,value:s}}if(Object.keys(n.price[i]).length===4){n.prepareCurrencyBlock(i)}}))}},{key:"currencyExists",value:function e(t){var i=this;this.seoAccount._helper.request("checkCurrencyExists",{currency:t},(function(e){var t=e.exists;if(t===false){i.prepareCurrencyBlocks();i.uiNodes.currencyBlock.style.display="block"}i.prepareCurrencyBlock(i.usedCurrency)}))}},{key:"addCurrency",value:function e(){var t=this;var i=document.querySelector(".seo-ads-currency-count");var a=document.querySelector(".seo-ads-currency-course");if(!i.value||!a){return}this.seoAccount._helper.request("addCurrency",{newCurrency:this.usedCurrency,course:a.value,amountCnt:i.value},(function(e){var i=e.success;if(i===false){return}t.uiNodes.currencyBlock.style.display="none";delete t.price[t.usedCurrency];t.prepareCurrencyBlock(t.usedCurrency)}))}},{key:"switchCollapsed",value:function e(t){var i=t.target.closest(".crm-ads-new-campaign-item");var a=i.querySelector(".crm-ads-new-campaign-item-content");if(i.classList.contains("crm-ads-new-campaign-item--hide")){i.classList.remove("crm-ads-new-campaign-item--hide");a.style.height=a.scrollHeight+"px"}else{i.classList.add("crm-ads-new-campaign-item--hide");a.style.height=a.scrollHeight+"px";setTimeout((function(){return a.style.height="0"}))}}},{key:"clipTitle",value:function e(t){if(!t){return}var i=t.textContent;var a=20;BX.cleanNode(t);var n=BX.create("span",{text:i});t.appendChild(n);var s=0;while(n.offsetHeight>a&&i.length>s){s=s+1;n.innerText=i.slice(0,-s)+"..."}}},{key:"onPostSelected",value:function e(t){if(t.eventId==="seo-ads-post-selected"&&t.data){if(!t.data.media_url){this.deActivateStage(this._STAGES.postSelected);return}var i=r.Tag.render(h||(h=babelHelpers.taggedTemplateLiteral([' \n\t\t\t<div class="crm-ads-new-campaign-item-post">\n\t\t\t   <div class="crm-ads-new-campaign-item-post-img" \n\t\t\t\t\tstyle="background-image: url(',')">\n\t\t\t   </div>\n\t\t\t   <span class="crm-ads-new-campaign-item-post-text">','</span>\n\t\t\t   <span class="crm-ads-new-campaign-item-post-delete"></span>\n\t\t\t</div>\n\t\t\t'])),t.data.media_url,r.Text.encode(t.data.caption||""));var a=document.querySelector(".crm-ads-new-campaign-item-posts");var n=document.querySelector(".crm-ads-new-campaign-item-post-new");var s=document.querySelector(".crm-ads-new-campaign-item-total-preview-img-value");if(n!==a.firstChild){a.removeChild(a.firstChild)}a.insertBefore(i,a.firstChild);r.Event.bind(i.querySelector(".crm-ads-new-campaign-item-post-delete"),"click",(function(){i.parentNode.removeChild(i)}));s.style.backgroundImage="url("+t.data.media_url+")";this.postData=t.data;var o=document.querySelector(".crm-ads-new-campaign-item-post-text");this.clipTitle(o);this.activateStage(this._STAGES.postSelected)}}},{key:"openPostSlider",value:function e(){if(this.uiNodes.instagramAccount.value){this.openSlider(this.postListUrl,{sessid:BX.bitrix_sessid(),componentParams:{ACCOUNT_ID:this.uiNodes.instagramAccount.value,CLIENT_ID:this.uiNodes.clientInput.value,TYPE:this.provider.TYPE}},this.onPostSelected)}}},{key:"onTargetPageSelected",value:function e(t){if(t.eventId==="seo-ads-target-post-selected"&&t.data){if(!t.data.targetUrl){this.deActivateStage(this._STAGES.pageSelected);return}document.querySelector(".seo-ads-target-url").textContent=t.data.targetUrl;this.uiNodes.form.targetUrl.value=t.data.targetUrl;this.activateStage(this._STAGES.pageSelected)}}},{key:"onFBAudienceConfigured",value:function e(t){if(t.eventId==="seo-fb-audience-configured"&&t.data){this.reInitAdCreator();if(!t.data){this.deActivateStage(this._STAGES.audienceSelected);return}this.adCreatorData.audienceConfig=t.data;this.activateStage(this._STAGES.audienceSelected);this.uiNodes.audienceSummary.innerHTML=this.buildAudienceSummary()}}},{key:"onCrmAudienceConfigured",value:function e(t){if(t.eventId==="seo-crm-audience-configured"&&t.data){this.reInitAdCreator();if(!t.data){this.deActivateStage(this._STAGES.audienceSelected);return}this.adCreatorData.crmAudienceConfig=t.data;this.activateStage(this._STAGES.audienceSelected);this.uiNodes.audienceSummary.innerHTML=this.buildAudienceSummary()}}},{key:"openTargetPageSlider",value:function e(){if(this.uiNodes.instagramAccount.value){this.storeBlockShow(false);this.openSlider(this.pageConfigurationUrl,{sessid:BX.bitrix_sessid(),targetUrl:this.uiNodes.form.targetUrl.value||"",cacheable:false},this.onTargetPageSelected)}}},{key:"openSlider",value:function e(t,i,a){var n={width:1150,cacheable:i.cacheable||true,allowChangeHistory:false,requestMethod:"post",requestParams:i};var s=BX.SidePanel.Slider.getEventFullName("onMessage");BX.removeAllCustomEvents(window,s,a.bind(this));BX.addCustomEvent(window,s,a.bind(this));BX.SidePanel.Instance.open(t,n)}},{key:"showAudienceExpertModeForm",value:function e(){if(this.uiNodes.instagramAccount.value){this.openSlider(this.audienceUrl,{sessid:BX.bitrix_sessid(),componentParams:{ACCOUNT_ID:this.uiNodes.instagramAccount.value,CLIENT_ID:this.uiNodes.clientInput.value,TYPE:this.provider.TYPE}},this.onFBAudienceConfigured)}}},{key:"showCrmAudienceExpertModeForm",value:function e(){if(this.uiNodes.instagramAccount.value){this.openSlider(this.crmAudienceUrl,{sessid:BX.bitrix_sessid(),componentParams:{TYPE:this.provider.TYPE}},this.onCrmAudienceConfigured)}}},{key:"initiateAutoAudienceMode",value:function e(){this.reInitAdCreator();this.adCreatorData.crmAudienceConfig.genders=[1,2];this.adCreatorData.crmAudienceConfig.ageFrom=25;this.adCreatorData.crmAudienceConfig.ageTo=45;this.activateStage(this._STAGES.audienceSelected);this.uiNodes.audienceSummary.innerHTML=r.Loc.getMessage("SEO_AD_BUILDER_AUDIENCE_MEN_WOMAN_25_45")}},{key:"buildAudienceSummary",value:function e(){var t="";if(this.adCreatorData.audienceConfig.genderTitles){t+="".concat(r.Loc.getMessage("SEO_AD_BUILDER_GENDER"),": ").concat(this.adCreatorData.audienceConfig.genderTitles.join(", ")," ")}if(this.adCreatorData.audienceConfig.ageFrom){t+="".concat(this.adCreatorData.audienceConfig.ageFrom," - ").concat(this.adCreatorData.audienceConfig.ageTo,"\n\t\t\t ").concat(r.Loc.getMessage("SEO_AD_BUILDER_YEARS_OLD")," <br/>")}if(this.adCreatorData.audienceConfig.interests){var i=[];this.adCreatorData.audienceConfig.interests.forEach((function(e){i.push(e.name)}));t+="".concat(r.Loc.getMessage("SEO_AD_BUILDER_INTERESTS"),": ").concat(i.join(", "),"<br/>")}if(this.adCreatorData.crmAudienceConfig.segmentInclude){t+="".concat(r.Loc.getMessage("SEO_AD_BUILDER_CRM_AUDIENCE"),"<br/>")}if(Object.keys(this.selectedRegions).length){var a=[];for(var n in this.selectedRegions){a.push(this.selectedRegions[n].title)}t+="".concat(r.Loc.getMessage("SEO_AD_BUILDER_REGION"),": ").concat(a.join(", "),"<br/>")}return t}},{key:"sendToModeration",value:function e(t){this.uiNodes.toModerationBtn.classList.add("ui-btn-wait");var i=this.uiNodes.form;if(Object.keys(this.completedStages).length<6){for(var a=this._STAGES.accountSelected;a<=this._STAGES.toModeration;a++){if(!this.completedStages[a]){this.scrollToStage(a);this.uiNodes.toModerationBtn.classList.remove("ui-btn-wait");return}}this.uiNodes.toModerationBtn.classList.remove("ui-btn-wait");return}var n=this.uiNodes.instagramAccount.options[this.uiNodes.instagramAccount.selectedIndex].dataset;var s={client_id:this.uiNodes.clientInput.value,budget:i.budget.value,duration:i.duration.value,targetUrl:i.targetUrl.value,accountId:this.uiNodes.account.value,instagramAccountId:n.actorId,pageId:n.pageId,body:this.postData.caption,mediaId:this.postData.id,permalink:this.postData.permalink,imageUrl:this.postData.media_url,countries:this.selectedRegions,interests:this.adCreatorData.audienceConfig.interests||[],ageFrom:this.adCreatorData.audienceConfig.ageFrom||"",ageTo:this.adCreatorData.audienceConfig.ageTo||"",genders:this.adCreatorData.audienceConfig.genders||""};var o=document.getElementById("bx-sender-letter-edit").querySelector("form");i.permalink.value=this.postData.permalink;i.pageId.value=s.pageId;i.body.value=this.postData.caption;i.mediaId.value=s.mediaId;i.imageUrl.value=s.imageUrl;i.instagramAccountId.value=s.instagramAccountId;i.interests.value=JSON.stringify(s.interests);i.ageFrom.value=s.ageFrom;i.ageTo.value=s.ageTo;i.genders.value=JSON.stringify(s.genders);i.regions.value=JSON.stringify(s.countries);var c=this.adCreatorData.crmAudienceConfig.segmentInclude||[];var d=this.adCreatorData.crmAudienceConfig.segmentExclude||[];for(var l=0;l<c.length;l++){var u=r.Tag.render(p||(p=babelHelpers.taggedTemplateLiteral(["<input type=\"hidden\" name='SEGMENT[INCLUDE][]'>"])));u.value=c[l];o.appendChild(u)}for(var h=0;h<d.length;h++){var g=r.Tag.render(m||(m=babelHelpers.taggedTemplateLiteral(["<input type=\"hidden\" name='SEGMENT[EXCLUDE][]'>"])));g.value=d[h];o.appendChild(g)}o.submit()}},{key:"activateStage",value:function e(t){var i=document.querySelector('[data-stage="'.concat(t,'"]'));var a=i.querySelector(".crm-ads-new-campaign-item-line");var n=i.querySelector(".crm-ads-new-campaign-item-number");var s=i.querySelector(".crm-ads-new-campaign-item-number-checker");if(a&&n){a.classList.remove("crm-ads-new-campaign-item--inactive");n.classList.remove("crm-ads-new-campaign-item--inactive")}if(s){s.style.display="block"}this.completedStages[t]=t;if(Object.keys(this.completedStages).length===5){this.activateStage(this._STAGES.toModeration)}if(Object.keys(this.completedStages).length<5){this.deActivateStage(this._STAGES.toModeration)}}},{key:"deActivateStage",value:function e(t){var i=document.querySelector('[data-stage="'.concat(t,'"]'));var a=i.querySelector(".crm-ads-new-campaign-item-line");var n=i.querySelector(".crm-ads-new-campaign-item-number");var s=i.querySelector(".crm-ads-new-campaign-item-number-checker");if(a&&n){a.classList.add("crm-ads-new-campaign-item--inactive");n.classList.add("crm-ads-new-campaign-item--inactive")}if(s){s.style.display="none"}delete this.completedStages[t];if(Object.keys(this.completedStages).length<6&&this.completedStages[this._STAGES.toModeration]){this.deActivateStage(this._STAGES.toModeration)}}},{key:"scrollToStage",value:function e(t){var i=document.querySelector('[data-stage="'.concat(t,'"]'));i.scrollIntoView({behavior:"smooth"})}},{key:"buildSelector",value:function e(){var t=this;var i=new c.TagSelector({id:"seo-ads-regions",dialogOptions:{id:"seo-ads-regions",context:"SEO_ADS_REGIONS",dropdownMode:true,compactView:true,showAvatars:false,width:350,height:250,recentTabOptions:{stub:true,stubOptions:{title:r.Loc.getMessage("UI_TAG_SELECTOR_START_INPUT")}},searchOptions:{allowCreateItem:false},events:{"Item:onSelect":function e(i){var a=i.data.item;t.selectedRegions[a.id]=a;t.uiNodes.audienceSummary.innerHTML=t.buildAudienceSummary()}},entities:[{id:"facebook_regions",searchable:true,dynamicSearch:true,options:{clientId:this.uiNodes.clientInput.value}}]}});i.renderTo(document.getElementById("seo-ads-regions"));i.getDialog().getRecentTab().setVisible(false);var a={iblockId:this.iBlockId,basePriceId:this.basePriceId,fields:{NAME:""},fileInputId:"",config:{ENABLE_SEARCH:true,ENABLE_IMAGE_CHANGE_SAVING:true}};this.productSelector=new n.ProductSelector("facebook-product-selector",a);s.EventEmitter.subscribe("BX.Catalog.ProductSelector:onChange",this.productSelectedEvent.bind(this))}},{key:"productSelectedEvent",value:function e(t){var i=this;var a=t.data.fields;this.seoAccount._helper.request("getProductUrl",{id:a.ID},(function(e){document.querySelector(".seo-ads-target-url").textContent=e;i.uiNodes.form.targetUrl.value=e;i.activateStage(i._STAGES.pageSelected)}))}},{key:"toCreateStoreSlider",value:function e(){if(!this.isCloud){this.openTargetPageSlider();return}var t={width:990,cacheable:true,allowChangeHistory:false,requestMethod:"get"};BX.SidePanel.Instance.open("/shop/stores/site/edit/0/?super=Y",t)}}]);return e}();var v;var f=function(){function e(t){babelHelpers.classCallCheck(this,e);this.helper=u.getCreated();this.last=null;this.stopLoading=false;this.loadInProgress=false;this._accountId=t.accountId;this._clientId=t.clientId;this._type=t.type;this.signedParameters=t.signedParameters;this.emptyBlock=document.querySelector(".seo-ads-empty-post-list-block");this.listContent=document.querySelector(".crm-order-instagram-view-list");this.dataContent=[];this.loader=new BX.Loader({target:document.querySelector(".crm-order-instagram-view")});this.init()}babelHelpers.createClass(e,[{key:"init",value:function e(){this.hideListContentBlock();var t=BX.SidePanel.Instance.getTopSlider().iframe.contentDocument;var i=new IntersectionObserver(this.loadPostList.bind(this),{root:t,rootMargin:"0px",threshold:1});i.observe(this.listContent);this.loadPostList()}},{key:"loadPostList",value:function e(){var t=this;if(this.loadInProgress){return}if(this.stopLoading){return}this.loader.show();this.loadInProgress=true;var i={clientId:this._clientId||null,type:this._type||null,accountId:this._accountId||null,last:this.last};BX.ajax.runComponentAction("bitrix:seo.ads.builder","getPostList",{mode:"class",signedParameters:this.signedParameters,data:i}).then((function(e){var i=e.data||{};if(i.error);else{t.successFn.apply(t,[i])}t.loadInProgress=false}),(function(){t.loadInProgress=false;t.loader.hide()}))}},{key:"showEmptyListBlock",value:function e(){this.emptyBlock.style.display="block"}},{key:"hideEmptyListBlock",value:function e(){this.emptyBlock.style.display="none"}},{key:"showListContentBlock",value:function e(){this.listContent.parentNode.style.display="block"}},{key:"hideListContentBlock",value:function e(){this.listContent.parentNode.style.display="none"}},{key:"successFn",value:function e(t){var i=this;var a=t.data;if(this.clientSelector){this.clientSelector.enable()}a.postList.forEach((function(e){var t=r.Tag.render(v||(v=babelHelpers.taggedTemplateLiteral(['\n\t\t\t\t\t<label class="crm-order-instagram-view-item" id="instItemID_','">\n\t\t\t\t\t\t<div class="crm-order-instagram-view-item-detail">\n\t\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t\t<span class="crm-order-instagram-view-item-img" style="background-image: url(',')"></span>\n\t\t\t\t\t\t\t\t<span class="crm-order-instagram-decal-container">\n\t\t\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t\t\t<svg width="67" height="16" viewBox="0 0 67 16" fill="none" xmlns="http://www.w3.org/2000/svg">\n\t\t\t\t\t\t\t\t\t\t\t<path d="M48.6026 0.306715C54.4273 0.290801 60.2679 0.306716 66.1244 0.290802C63.0688 5.35159 60.0292 10.3805 56.9736 15.4413C56.9577 15.3777 56.9418 15.3299 56.9418 15.2981C56.7508 13.9931 56.5439 12.6722 56.353 11.3672C56.162 10.0782 55.971 8.78911 55.7641 7.50004C55.6845 6.95895 55.605 6.41785 55.5254 5.86085C55.5095 5.74945 55.4458 5.66988 55.3503 5.60622C54.8252 5.19245 54.3 4.77867 53.7589 4.36489C52.0879 3.05991 50.401 1.75493 48.7299 0.449946C48.6822 0.402203 48.6345 0.370374 48.5708 0.32263C48.5867 0.338545 48.5867 0.322629 48.6026 0.306715ZM56.4962 5.66988C56.8463 7.96156 57.1805 10.2532 57.5306 12.5449C57.642 12.4335 63.976 1.96182 64.0078 1.81859C61.4933 3.10765 58.9947 4.38081 56.4962 5.66988ZM62.7824 1.34115C62.7824 1.32524 62.7665 1.32524 62.7665 1.30932C62.3845 1.2775 51.6105 1.2775 51.4672 1.32524C52.9791 2.50291 54.4751 3.66466 55.971 4.82641C58.2468 3.66466 60.5066 2.50291 62.7824 1.34115Z" fill="#999"/>\n\t\t\t\t\t\t\t\t\t\t\t<path d="M9.46094 15.2344C8.60547 14.3984 4.79192 10.6375 2.65772 8.51853C2.49858 8.3753 2.35535 8.21616 2.21212 8.05702C1.44823 7.26129 1.03445 6.32234 0.954879 5.24016C0.859393 4.01475 1.1936 2.91666 1.95749 1.96179C2.67364 1.07058 3.59667 0.481747 4.74251 0.306688C6.66816 0.00431397 8.19594 0.672722 9.34178 2.24825C9.37361 2.28008 9.38952 2.31191 9.40544 2.34374C9.40544 2.34374 9.42135 2.35965 9.45318 2.37556C9.48501 2.32782 9.53275 2.26416 9.5805 2.21642C10.2012 1.34113 11.0128 0.752293 12.0313 0.434004C12.4769 0.290774 12.9384 0.258947 13.4 0.258947C14.0206 0.258947 14.6095 0.370347 15.1665 0.640892C16.5828 1.29338 17.49 2.37556 17.8242 3.88743C18.1425 5.31973 17.8242 6.64063 16.933 7.80238C16.7738 8.00927 16.5828 8.18433 16.3919 8.37531C14.9277 9.82352 13.4795 11.2717 12.0154 12.7199C11.1923 13.543 10.2422 14.4922 9.46094 15.2344ZM9.42135 13.818C9.51684 13.7226 9.61233 13.643 9.6919 13.5634C10.233 13.0223 10.79 12.4812 11.3311 11.9401C12.827 10.4601 14.3389 8.98005 15.8349 7.4841C15.9622 7.3727 16.0736 7.24538 16.1691 7.10215C17.0125 5.95631 17.1717 4.71498 16.6306 3.39409C15.9622 1.77081 14.1479 0.879609 12.4292 1.32521C11.5539 1.54801 10.8537 2.04136 10.3444 2.78934C10.0579 3.21903 9.8033 3.64872 9.51684 4.07841C9.48501 4.12615 9.45318 4.1739 9.42135 4.23755C9.3577 4.14207 9.30995 4.07841 9.26221 3.99884C8.99166 3.58506 8.73703 3.15537 8.46649 2.7416C7.65485 1.56393 6.19073 0.975095 4.80617 1.27747C2.60998 1.7549 1.40048 3.99883 2.13255 6.09954C2.32352 6.64063 2.64181 7.10215 3.05558 7.51593C3.81948 8.2639 4.58337 9.01188 5.33135 9.75986C6.58859 11.0012 7.84583 12.2584 9.11898 13.4997C9.21447 13.6111 9.30995 13.7066 9.42135 13.818Z" fill="#999"/>\n\t\t\t\t\t\t\t\t\t\t\t<path d="M41.4411 14.9002C41.282 14.8843 41.1387 14.8684 40.9796 14.8525C40.343 14.7888 39.7223 14.7093 39.0858 14.6456C38.5447 14.5819 38.0195 14.5501 37.4784 14.4705C37.2874 14.4546 37.1442 14.4865 36.9851 14.566C36.2371 14.9002 35.4414 15.1071 34.6297 15.1708C32.9269 15.2981 31.3354 14.948 29.8872 14.009C28.5504 13.1337 27.5796 11.9561 26.9749 10.476C26.7043 9.82352 26.5452 9.13921 26.4815 8.43897C26.3383 6.60881 26.7203 4.92188 27.7865 3.42593C28.9642 1.77082 30.5397 0.736386 32.529 0.35444C32.9269 0.274868 33.3407 0.227125 33.7385 0.243039C34.0727 0.258954 34.4069 0.243039 34.7411 0.274868C35.7278 0.370354 36.6668 0.656814 37.5262 1.15016C39.2927 2.13686 40.4862 3.60098 41.1069 5.54254C41.3138 6.19503 41.4093 6.86344 41.4252 7.54776C41.457 8.50263 41.2979 9.40975 40.9796 10.301C40.9478 10.3964 40.9478 10.4919 40.9478 10.5874C41.0432 11.4627 41.1387 12.338 41.2342 13.1974C41.2979 13.7066 41.3456 14.2159 41.4093 14.7411C41.4411 14.7888 41.4411 14.8366 41.4411 14.9002ZM40.3271 13.8021C40.3271 13.7544 40.3271 13.7385 40.3271 13.7226C40.2793 13.2292 40.2157 12.7518 40.1679 12.2584C40.1043 11.6537 40.0406 11.0649 39.977 10.4601C39.9611 10.3487 39.977 10.2691 40.0088 10.1577C40.4385 9.09146 40.5499 7.97745 40.4226 6.84753C40.3271 6.03589 40.0725 5.272 39.6587 4.57177C38.3219 2.1846 35.7119 0.895532 33.0065 1.29339C31.7333 1.48437 30.6193 2.00954 29.6644 2.853C27.8502 4.46036 27.0863 6.83161 27.6274 9.18695C28.0889 11.1444 29.2347 12.5926 31.0012 13.5316C31.7492 13.9294 32.5449 14.1522 33.3884 14.2159C33.8499 14.2477 34.2955 14.2477 34.757 14.2C35.505 14.1045 36.2212 13.8817 36.9055 13.5475C37.0487 13.4838 37.176 13.4679 37.3352 13.4838C37.6694 13.5316 37.9877 13.5634 38.3219 13.5952C38.7675 13.643 39.2131 13.6907 39.6587 13.7385C39.8656 13.7544 40.0884 13.7703 40.3271 13.8021Z" fill="#999"/>\n\t\t\t\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t\t<span>\n\t\t\t\t\t\t\t\t\t\t<svg width="13" height="14" viewBox="0 0 13 14" fill="none" xmlns="http://www.w3.org/2000/svg">\n\t\t\t\t\t\t\t\t\t\t\t<path fill-rule="evenodd" clip-rule="evenodd" d="M6.145 8.0856L0.5 13.7847V0.5H12.5V13.7847L6.855 8.0856L6.5 7.727L6.145 8.0856Z" stroke="#999"/>\n\t\t\t\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t</span>\n\t\t\t\t\t\t\t\t<div class="crm-order-instagram-view-item-decs-block">\n\t\t\t\t\t\t\t\t\t<div class="crm-order-instagram-view-item-decs">\n\t\t\t\t\t\t\t\t\t\t<span class="crm-order-instagram-view-item-name">','</span>\n\t\t\t\t\t\t\t\t\t\t<span class="crm-order-instagram-view-item-edit"></span>\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<div class="crm-order-instagram-view-item-checkbox-container">\n\t\t\t\t\t\t\t\t<input class="crm-order-instagram-view-item-input" \n\t\t\t\t\t\t\t\t\t\ttype="checkbox" \n\t\t\t\t\t\t\t\t\t\tid="','" \n\t\t\t\t\t\t\t\t\t\tdata-id="','"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t<div class="crm-order-instagram-view-item-input-title">','</div>\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t\t<div class="crm-order-instagram-view-item-selected-icon">\n\t\t\t\t\t\t\t<svg width="13" height="10" viewBox="0 0 13 10" fill="none" xmlns="http://www.w3.org/2000/svg">\n\t\t\t\t\t\t\t\t<path fill-rule="evenodd" clip-rule="evenodd" d="M4.87744 6.02868L10.9842 0L12.8322 1.85828L4.90632 9.7162L4.87744 9.68717L4.84857 9.7162L0 5.02339L1.84802 3.16511L4.87744 6.02868Z" fill="white"/>\n\t\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t</div>\n\t\t\t\t\t</label>'])),e.id,e.media_url,BX.util.htmlspecialchars(e.caption||""),e.id,e.id,r.Loc.getMessage("SEO_AD_BUILDER_POST_SELECTOR_SELECT"));i.listContent.appendChild(t);r.Event.bind(t,"click",i.selectPost.bind(i));i.dataContent[e.id]=e;i.showListContentBlock();var a=new BX.UI.TextCrop({rows:3,target:t.querySelector(".crm-order-instagram-view-item-name")});a.init()}));this.loader.hide();if(a.last){this.last=a.last;return}if(Object.keys(this.dataContent).length===0){this.hideListContentBlock();this.showEmptyListBlock()}this.stopLoading=true}},{key:"selectPost",value:function e(t){var i=t.target;var a=i.dataset.id;document.querySelectorAll(".crm-order-instagram-view-item-input").forEach((function(e){e.checked=a===e.dataset.id}));document.querySelectorAll(".crm-order-instagram-view-item").forEach((function(e){BX.removeClass(e,"crm-order-instagram-view-item-selected")}));BX.addClass(document.querySelector("#instItemID_"+a),"crm-order-instagram-view-item-selected");BX.SidePanel.Instance.close();BX.SidePanel.Instance.postMessage(window,"seo-ads-post-selected",this.dataContent[a])}}]);return e}();var y=function(){function e(t){babelHelpers.classCallCheck(this,e);this.helper=u.getCreated();this.last=null;this._accountId=t.accountId;this._clientId=t.clientId;this._type=t.type;this.signedParameters=t.signedParameters;this.emptyBlock=document.querySelector(".seo-ads-empty-post-list-block");this.listContent=document.querySelector(".crm-order-instagram-view-list");this.dataContent=[];this.selectedInterest={};this.loader=new BX.Loader({target:document.querySelector(".crm-order-instagram-view")});this.rangeInput=document.querySelector(".crm-ads-new-campaign-item-runner-value");this.inputMax=BX("max");this.inputMin=BX("min");this.MAX_VALUE=65;this.MIN_VALUE=13;this.init()}babelHelpers.createClass(e,[{key:"init",value:function e(){var t=this;document.querySelectorAll(".crm-ads-new-campaign-item-runner-input").forEach((function(e){var i=e.closest(".crm-ads-new-campaign-item-runner-block--double");if(i){t.setDoubleInputPosition();t.setDoubleLabelPosition(e);r.Event.bind(e,"change",t.onDoubleInputRange.bind(t));r.Event.bind(e,"input",t.onDoubleInputRange.bind(t))}else{r.Event.bind(e,"change",t.onInputRange.bind(t));r.Event.bind(e,"input",t.onInputRange.bind(t))}}));this.buildSelector()}},{key:"checkSex",value:function e(){}},{key:"onInputRange",value:function e(t){var i=t.target.closest(".crm-ads-new-campaign-item-runner-block").children[0].children[0];var a=t.target.value;if(a<this.MIN_VALUE){t.target.value=this.MIN_VALUE}i.textContent=t.target.value;this.rangeInput.style.width=t.target.offsetWidth*t.target.value/65+"px"}},{key:"onDoubleInputRange",value:function e(t){this.setDoubleLabelPosition(t.target);this.setDoubleInputPosition()}},{key:"setDoubleLabelPosition",value:function e(t){var i=t.value;var a=t.previousElementSibling;if(i<this.MIN_VALUE){t.value=this.MIN_VALUE}a.children[0].textContent=t.value;a.style.left=(i-this.MIN_VALUE)/(this.MAX_VALUE-this.MIN_VALUE)*(t.offsetWidth-70)+20+"px"}},{key:"setDoubleInputPosition",value:function e(){var t=BX("label-max").getBoundingClientRect().left;var i=BX("label-min").getBoundingClientRect().left;var a=Math.min(t,i);if(t===a){this.rangeInput.style.width=(this.inputMin.value-this.MIN_VALUE)/(this.MAX_VALUE-this.MIN_VALUE)*(this.inputMin.offsetWidth-40)+20-((this.inputMax.value-this.MIN_VALUE)/(this.MAX_VALUE-this.MIN_VALUE)*(this.inputMax.offsetWidth-40)+20)+"px";this.rangeInput.style.left=(this.inputMax.value-this.MIN_VALUE)/(this.MAX_VALUE-this.MIN_VALUE)*(this.inputMax.offsetWidth-40)+20+"px"}else{this.rangeInput.style.width=(this.inputMax.value-this.MIN_VALUE)/(this.MAX_VALUE-this.MIN_VALUE)*(this.inputMax.offsetWidth-40)+20-((this.inputMin.value-this.MIN_VALUE)/(this.MAX_VALUE-this.MIN_VALUE)*(this.inputMin.offsetWidth-40)+20)+"px";this.rangeInput.style.left=(this.inputMin.value-this.MIN_VALUE)/(this.MAX_VALUE-this.MIN_VALUE)*(this.inputMin.offsetWidth-40)+20+"px"}}},{key:"buildSelector",value:function e(){var t=this;var i=new c.TagSelector({id:"seo-ads-interests",dialogOptions:{id:"seo-ads-interests",context:"SEO_ADS_INTERESTS",dropdownMode:true,searchOptions:{allowCreateItem:false},width:350,height:250,recentTabOptions:{stub:true,stubOptions:{title:r.Loc.getMessage("UI_TAG_SELECTOR_START_INPUT")}},events:{"Item:onSelect":function e(i){var a=i.data.item;t.selectedInterest[a.id]=a;var n=0;for(var s in t.selectedInterest){n+=t.selectedInterest[s].customData.get("audienceSize")}document.querySelector(".crm-ads-new-campaign-item-cost-value").textContent=n;return}},entities:[{id:"facebook_interests",searchable:true,dynamicSearch:true,options:{clientId:this._clientId}}]}});i.renderTo(document.getElementById("seo-ads-interests"))}},{key:"showEmptyListBlock",value:function e(){this.emptyBlock.style.display="block"}},{key:"hideEmptyListBlock",value:function e(){this.emptyBlock.style.display="none"}},{key:"showListContentBlock",value:function e(){this.listContent.parentNode.style.display="block"}},{key:"hideListContentBlock",value:function e(){this.listContent.parentNode.style.display="none"}},{key:"apply",value:function e(t){t.classList.remove("ui-btn-wait");BX.SidePanel.Instance.close();var i=[];var a=[];if(document.getElementById("male").checked){i.push(1);a.push(document.getElementById("male").parentNode.querySelector("span").innerText)}if(document.getElementById("female").checked){i.push(2);a.push(document.getElementById("female").parentNode.querySelector("span").innerText)}var n=[];Object.entries(this.selectedInterest).forEach((function(e){var t=babelHelpers.slicedToArray(e,2),i=t[0],a=t[1];n.push({id:a.id,name:a.title})}));BX.SidePanel.Instance.postMessage(window,"seo-fb-audience-configured",{interests:n,ageFrom:Math.min(this.inputMin.value,this.inputMax.value),ageTo:Math.max(this.inputMin.value,this.inputMax.value),genderTitles:a,genders:i})}}]);return e}();var S=function(){function e(){babelHelpers.classCallCheck(this,e)}babelHelpers.createClass(e,null,[{key:"apply",value:function e(t){BX.SidePanel.Instance.close();BX.SidePanel.Instance.postMessage(window,"seo-crm-audience-configured",{segmentInclude:window.senderSegmentSelector.selectorInclude.selector.getTilesId()||[],segmentExclude:window.senderSegmentSelector.selectorExclude.selector.getTilesId()||[]});setTimeout((function(){t.classList.remove("ui-btn-wait")}),200)}}]);return e}();var C=function(){function e(){babelHelpers.classCallCheck(this,e);this.helper=u.getCreated();this.targetUrlBlock=document.querySelector(".seo-ads-target-url");return this}babelHelpers.createClass(e,[{key:"apply",value:function e(t){if(!this.validateUrl(this.targetUrlBlock.value)){this.removeWait(t);return}BX.SidePanel.Instance.close();BX.SidePanel.Instance.postMessage(window,"seo-ads-target-post-selected",{targetUrl:this.targetUrlBlock.value});this.removeWait(t)}},{key:"removeWait",value:function e(t){setTimeout((function(){t.classList.remove("ui-btn-wait")}),200)}},{key:"cancel",value:function e(){BX.SidePanel.Instance.close()}},{key:"validateUrl",value:function e(t){return/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(t)}}]);return e}();e.Helper=u;e.SeoAccount=d;e.SeoPostSelector=f;e.SeoAudience=y;e.SeoCrmAudience=S;e.PageConfiguration=C;e.SeoAdBuilder=g})(this.BX.Seo=this.BX.Seo||{},BX.Main,BX.UI,BX.Seo.Ads,BX.Catalog,BX.Event,BX.UI,BX,BX.UI.EntitySelector);
//# sourceMappingURL=seoadbuilder.bundle.map.js